<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['visit:managed:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visit:managed:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visit:managed:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['visit:managed:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="managedList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="限期整改ID" align="center" prop="wmId" />-->
      <el-table-column label="关联项目" align="center" prop="wmPId"/>
      <el-table-column label="下发单位" align="center" prop="wmUnit"/>
      <el-table-column label="下达原因" align="center" prop="wmCause"/>
      <el-table-column label="类型" align="center" prop="wmType"/>
      <el-table-column label="下达文号" align="center" prop="wmNumber"/>
      <el-table-column label="治理内容" align="center" prop="wmContent"/>
      <el-table-column label="要求完成时间" align="center" prop="wmCompleteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.wmCompleteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成情况" align="center" prop="wmCompleteSituation"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['visit:managed:edit']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['visit:managed:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改限期整改对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="60%">

      <el-form ref="form" :model="form" :rules="rules" class="clearfix  m-f-a-i" label-width="130px">
        <div class="content-left" style="width: 40%">
          <el-form-item label="关联项目" prop="wmPId">
            <el-input v-model="form.wmPId" placeholder="请输入关联项目"/>
          </el-form-item>
          <el-form-item label="下发单位" prop="wmUnit">
            <el-input v-model="form.wmUnit" placeholder="请输入下发单位"/>
          </el-form-item>
          <el-form-item label="下达原因" prop="wmCause">
            <el-input v-model="form.wmCause" placeholder="请输入下达原因"/>
          </el-form-item>
          <el-form-item label="类型" prop="wmType">
            <el-select v-model="form.wmType" placeholder="请选择类型">
              <!--            整改、挂牌督办、限期治理-->
              <el-option label="整改" value="1"/>
              <el-option label="挂牌督办" value="2"/>
              <el-option label="限期治理" value="3"/>
            </el-select>
          </el-form-item>
          <el-form-item label="下达文号" prop="wmNumber">
            <el-input v-model="form.wmNumber" placeholder="请输入下达文号"/>
          </el-form-item>
          <el-form-item label="治理内容">
            <editor v-model="form.wmContent" :min-height="192"/>
          </el-form-item>
          <el-form-item label="要求完成时间" prop="wmCompleteTime">
            <el-date-picker clearable size="small"
                            v-model="form.wmCompleteTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择要求完成时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="完成情况" prop="wmCompleteSituation">
            <el-input v-model="form.wmCompleteSituation" placeholder="请输入完成情况"/>
          </el-form-item>
        </div>
        <div class="content-left" style="float: right; width: 45%">
          <el-form-item label="限期治理">
            <fileUpload v-model="form.data1"/>
          </el-form-item>
          <el-form-item label="整改报告">
            <fileUpload v-model="form.data2"/>
          </el-form-item>
          <el-form-item label="试运行申请">
            <fileUpload v-model="form.data3"/>
          </el-form-item>
          <el-form-item label="试运行批复">
            <fileUpload v-model="form.data4"/>
          </el-form-item>
          <el-form-item label="验收申请">
            <fileUpload v-model="form.data5"/>
          </el-form-item>
          <el-form-item label="验收监测报告">
            <fileUpload v-model="form.data6"/>
          </el-form-item>
          <el-form-item label="正式验收批复">
            <fileUpload v-model="form.data7"/>
          </el-form-item>
          <el-form-item label="附属资料">
            <fileUpload v-model="form.data8"/>
          </el-form-item>
        </div>
        <!--        <el-form-item label="统一社会信用代码" prop="epId">
                  <el-input v-model="form.epId" placeholder="请输入统一社会信用代码" />
                </el-form-item>
                <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addManaged, delManaged, exportManaged, getManaged, listManaged, updateManaged} from "@/api/visit/managed";

export default {
  name: "Managed",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 限期整改表格数据
      managedList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询限期整改列表 */
    getList() {
      this.loading = true;
      listManaged(this.queryParams).then(response => {
        this.managedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wmId: null,
        wmPId: null,
        wmUnit: null,
        wmCause: null,
        wmType: null,
        wmNumber: null,
        wmContent: null,
        wmCompleteTime: null,
        wmCompleteSituation: null,
        data1: null,
        data2: null,
        data3: null,
        data4: null,
        data5: null,
        data6: null,
        data7: null,
        data8: null,
        epId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wmId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加限期整改";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const wmId = row.wmId || this.ids
      getManaged(wmId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改限期整改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.wmId != null) {
            updateManaged(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManaged(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wmIds = row.wmId || this.ids;
      this.$confirm('是否确认删除限期整改编号为"' + wmIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delManaged(wmIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有限期整改数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportManaged(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
